//
//  SelectionButton.m
//  FangXinLang
//
//  Created by AJY on 16/9/18.
//  Copyright © 2016年 AJY. All rights reserved.
//

#import "SelectionButton.h"

#import "BYSelectNewBar.h"
#import "BYSelectionDetails.h"
#define ScreenW [UIScreen mainScreen].bounds.size.width
#define ScreenH [UIScreen mainScreen].bounds.size.height
@interface SelectionButton()
@property(nonatomic,strong)BYSelectionDetails *selection_details;
@end
@implementation SelectionButton


/******************************
 
 初始化ArrowButton
 
 ******************************/
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setImage:[UIImage imageNamed:@"Arrow.png"] forState:0];
        [self setImage:[UIImage imageNamed:@"Arrow.png"] forState:1<<0];
        //self.backgroundColor = Color_maingray;
        [self addTarget:self
                 action:@selector(ArrowClick:)
       forControlEvents:1 << 6];
        [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(ArrowClick:)
                                                     name:@"arrow_change"
                                                   object:nil];
    }
    return self;
}

-(void)ArrowClick:(UIButton *)sender{
    sender.selected= !sender.selected;
    
        self.Newbar.hidden = (self.Detail.frame.origin.y<0)?NO:YES;
    [UIView animateWithDuration:0.7     animations:^{
        CGAffineTransform rotation = self.imageView.transform;
        self.imageView.transform = CGAffineTransformRotate(rotation,M_PI);
        self.Detail.transform = (self.Detail.frame.origin.y<0)?CGAffineTransformMakeTranslation(0, [UIScreen mainScreen].bounds.size.height):CGAffineTransformMakeTranslation(0, -[UIScreen mainScreen].bounds.size.height);
        
    }];
    if(!sender.selected)
    {
        self.selection_details = [[BYSelectionDetails alloc] initWithFrame:CGRectMake(0, 120-ScreenH, ScreenW, ScreenH-120)];
        [[UIApplication sharedApplication].keyWindow.rootViewController.view addSubview: self.selection_details];
        
        self.Detail = self.selection_details;
    }
        

}

- (CGRect)imageRectForContentRect:(CGRect)contentRect{
    CGFloat image_width = 18;
    return CGRectMake((contentRect.size.width-image_width)/2, (30-image_width)/2, image_width, image_width);
}
@end
